/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.system.mapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.springblade.modules.repair.vo.DeptAddressListUserVO;
import org.springblade.modules.system.entity.Role;
import org.springblade.modules.system.entity.UserInfo;
import org.springblade.modules.system.excel.UserExcel;
import org.springblade.modules.system.entity.User;
import org.springblade.modules.system.vo.AppUserTenantInfoVO;
import org.springblade.modules.system.vo.SimpleUserVO;
import org.springblade.modules.system.vo.TenantInfoVO;
import org.springblade.modules.system.vo.UserVO;

import java.util.List;

/**
 * Mapper 接口
 *
 * @author Chill
 */
public interface UserMapper extends BaseMapper<User> {

	/**
	 * 自定义分页
	 *
	 * @param page
	 * @param user
	 * @param deptIdList
	 * @param tenantId
	 * @return
	 */
	List<User> selectUserPage(IPage<User> page, @Param("user") User user, @Param("deptIdList") List<Long> deptIdList, @Param("tenantId") String tenantId);

	/**
	 * 获取用户
	 *
	 * @param tenantId
	 * @param phone
	 * @param password
	 * @return
	 */
	User getUser(String tenantId, String phone, String password);

	/**
	 * 获取用户
	 *
	 * @param tenantId
	 * @param account 账号或手机号
	 * @param password
	 * @return
	 */
	User getUserByPhoneOrAccount(String tenantId, String account, String password);

	/**
	 * 获取导出用户数据
	 *
	 * @param queryWrapper
	 * @return
	 */
	List<UserExcel> exportUser(@Param("ew") Wrapper<User> queryWrapper);

	/**
	 * 根据用户id获取维保公司名称
	 * @param userId 用户id
	 * @return 维保公司名称
	 */
    String getUserRealNameAndCompanyName(@Param("userId") Long userId);

	/**
	 * 检查用户是否是维保人员
	 * @param userId
	 * @return
	 */
	Long isMaintain(@Param("userId") Long userId);

    List<TenantInfoVO> getTenantInfoByPhone(String phone);

    UserInfo getuserGroupInfo(@Param("userId") Long userId);

	/**
	 * 根据部门与角色查找用户
	 * @param deptId
	 * @param roleId
	 * @return
	 */
    List<SimpleUserVO> getUserByDeptAndRole(@Param("deptId") Long deptId, @Param("roleId") Long roleId);

	/**
	 * 根据部门与角色查找用户
	 * @param deptId
	 * @param roleId
	 * @return
	 */
	List<Long> getUserIdByDeptAndRole(@Param("deptId") Long deptId, @Param("roleId") Long roleId);

	/**
	 * 获取用户基础信息
	 * @param userId
	 * @return
	 */
	SimpleUserVO getSimpleUserInfo(@Param("userId") Long userId);

    String getOpenIdByPhone(@Param("phone") String phone);

	/**
	 * 根据角色id查找用户
	 * @param tenantId
	 * @param roleId
	 * @return
	 */
	List<Long> getUserByRoleId(@Param("tenantId") String tenantId, @Param("roleId") Long roleId);

	/**
	 * 批量获取用户信息
	 * @param userIds
	 * @return
	 */
    List<UserVO> getUserList(@Param("userIds") List<Long> userIds);

    List<Long> listUserByDeptIds(@Param("userDeptList") List<Long> userDeptList);

	/**
	 * 根据部门id集合统计所有用户关注公众号状态
	 * @param deptIds
	 * @return
	 */
    Integer countUserSubscribe(@Param("deptIds") List<Long> deptIds);

	/**
	 * 根据部门id获取用户通讯录列表信息
	 * @param deptId
	 * @return
	 */
	List<DeptAddressListUserVO> selectDeptUser(@Param("deptId") Long deptId);

	Integer countUserByDept(@Param("deptIds") List<Long> deptIds);

	@InterceptorIgnore(tenantLine = "on")
    List<SimpleUserVO> getSimpleUserInfoByElevatorUseType(@Param("elevatorId") Long elevatorId,@Param("useType")  Integer useType);

	@InterceptorIgnore(tenantLine = "on")
    List<SimpleUserVO> getAdminInfoByTenant(String tenantId);

    List<String> getDeptNames(Long userId);

	@InterceptorIgnore(tenantLine = "on")
	SimpleUserVO getSimpleEstateUserByPhone(String phone);

	@InterceptorIgnore(tenantLine = "on")
	String getEstateOpenIdByPhone(String phone);

    List<SimpleUserVO> selectElevatorSubUser(Long elevatorId);

	/**
	 * 根据用户id查询用户所属角色
	 * @param userId
	 * @return
	 */
	List<Role> getRoleByUserId(Long userId);


	/**
	 * 根据code值获取用户
	 * @param roleCode
	 * @return 数据集
	 */
    List<User> getUserListOfRoleCode(@Param("roleCode") String roleCode,@Param("tenantId")String tenantId);

	/**
	 * 获取用户的app推送的设备id
	 * @param userId 用户id
	 * @return 数据集
	 */
	String getUserAppPushId(Long userId);

	/**
	 * 根据部门集合与角色别名查找用户
	 * @param deptIds
	 * @param roleAlias
	 * @return
	 */
	List<SimpleUserVO> getUserByDeptIdsAndRoleAlias(@Param("deptIds") String deptIds, @Param("roleAlias") String roleAlias);

	/**
	 * 根据角色别名查找用户
	 * @param roleAlias 租户别名
	 * @param tenantId
	 * @return
	 */
	List<SimpleUserVO> getUserByRoleAlias(@Param("roleAlias") String roleAlias, @Param("tenantId") String tenantId);

    List<SimpleUserVO> listUserSimpleInfo(@Param("userIds") List<Long> userIds);

	List<AppUserTenantInfoVO> getAppUserTenantInfoByPhone(String phone);

	List<AppUserTenantInfoVO> getAppUserTenantInfoByPhoneAndPassword(@Param("phone") String phone, @Param("password") String password);
}
